package logic

import (
	"context"
	"user-login1/userrpc/userrpc"

	"user-login1/api/internal/svc"
	"user-login1/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type WechatRegisterLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewWechatRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WechatRegisterLogic {
	return &WechatRegisterLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *WechatRegisterLogic) WechatRegister(req *types.WechatRegisterRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	register, err := l.svcCtx.UserRpc.WechatRegister(l.ctx, &userrpc.WechatRegisterRequest{
		Mobile:     req.Mobile,
		Password:   req.Password,
		HeadImage:  req.HeadImage,
		NickName:   req.NickName,
		Address:    req.Address,
		WechatCode: req.WechatCode,
		SmsCode:    req.SmsCode,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "注册成功",
		Code:    200,
		Data:    register,
	}, nil
}
